/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fait.ferm.persists;

import fait.ferm.global.Glob;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Greg
 */
public class Credit_type extends PersistsObject {
    public int years;
    public double percent;
    public String name;
    
    public Credit_type(int pId) throws Exception {
        super(pId);
        table = "credit_type";
        load();
    }
    
    @Override
    public void load() throws Exception {
        boolean notSuccessfully=true;
		if(id==-1) {
			throw new Exception("Объект "+table+" отсутствует в базе");
		}	
		try (Statement st = con.createStatement()) {
			String q = "SELECT years, percent, name FROM "+table+" WHERE id = " + id;
			ResultSet rs = st.executeQuery(q);
			if(rs.next()){
				notSuccessfully=false;
                years = rs.getInt("years");
                percent = rs.getDouble("percent");
                name = rs.getString("name");
			}
			rs.close();
		}
		if(notSuccessfully) {
			throw new Exception("Объект "+table+" не загружен");
        }
    }

    @Override
    protected void update() throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected void createNew() throws SQLException, Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
